package com.myspace.server.blog.controller;

import com.myspace.server.base.util.JsonView;
import com.myspace.server.base.util.JsonViewFactory;
import com.myspace.server.blog.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章分类控制器
 * @author peng.zhang
 */
@Api(tags = {"blog", "blog-CategoryController"})
@RestController
@RequestMapping(value = "/blog/category")
public class CategoryController {

    private CategoryService categoryService;

    @Autowired
    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @ApiOperation(value = "文章分类", notes = "查询所有文章类别！")
    @GetMapping
    public JsonView getCategoryList() {
        JsonView jsonView = JsonViewFactory.createJsonView();
        try {
            jsonView.successPack(categoryService.getCategoryList());
        } catch (Exception e) {
            jsonView.errorPack("getCategoryList(/blog/category) error", e);
        }
        return jsonView;
    }

}
